<!--20210525  zaq  新建分组,完成调试-->
<template>
  <div>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="选择模板">
        <el-select v-model="form.kind" placeholder="请选择">
          <el-option
              v-for="item in kindTextGroups"
              :key="item.tgId"
              :label="item.tgName"
              :value="item.tgId">
            <span style="float: left">{{item.tgName}}</span>&#12288;&#12288;
            <span style="color: #72767b;float: right;font-size: 13px">{{item.tgText}}</span>
          </el-option>
        </el-select>

      </el-form-item>
      <el-form-item label="分类名称">
        <el-input
            type="text"
            placeholder="请输入内容"
            v-model="form.name"
            maxlength="20"
            show-word-limit
        ></el-input>
      </el-form-item>
      <el-form-item label="备注">
        <el-input
            type="textarea"
            :rows="2"
            placeholder="请输入内容"
            v-model="form.text"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="submit">创建</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import {getKindTextGroup_0000,insert_16111} from "../../api";

export default {
  name: "Instert_text_group",
  data(){
    return{
      kingTextGroup:{
        delete: false,
        tgId: 1,
        tgName: "默认模板",
        tgTable: "ASP_TEXT_RECORD_DEFAULT",
        tgText: "default",
      },
      form:{
        name:null,
        kind:null,
        text:null
      },
      kindTextGroups:null,
    }
  },
  methods:{
    submit(){
      const _this=this
      var form =this.form
      //合法性验证
      if(form.kind==null){
        _this.$message({
          type: 'error',
          message: '分组不能为空'
        });
      }else if(form.name==null||form.name.trim()==""){
        _this.$message({
          type: 'error',
          message: '名称不能为空'
        });
      }else{
        var body={
          code:-1,
          note:'',
          gName:form.name,
          gText:form.text,
          uId:sessionStorage.getItem("uId"),
          tgId:form.kind,
        }
        console.log(body)
        insert_16111(body).then(resp=>{
          if(resp.code>0){
            _this.$message({
              type: 'success',
              message: '新增说说分组成功'
            });
          }else{
            _this.$message({
              type: 'error',
              message: '新增说说分组失败：'+resp.note
            });
          }
        }).catch(err=>{
          _this.$message({
            type: 'error',
            message: '新增说说分组失败：'+err
          });
        })
      }


    },
    getKindTextGroup(){
      const  _this=this
      getKindTextGroup_0000().then(resp=>{
        console.log(resp)
        _this.kindTextGroups=resp
      }).catch(error=>{
        console.log(error)
      })
    }
  },
  created() {
    this.getKindTextGroup()
  }
}
</script>

<style scoped>

</style>